package com.wdl.modules.myhouse.security.deprecated.mailLogin;

import com.wdl.modules.myhouse.security.entity.UserInfo;
import com.wdl.modules.myhouse.service.UserService;
import com.wdl.modules.myhouse.utils.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.InternalAuthenticationServiceException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Component;

/**
 * 邮箱登录实现并未使用当前api,由于创作辛苦,暂时保留,以作后用
 */
@Component
@Deprecated
public class MailLoginProvider implements AuthenticationProvider {

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private UserService userService;

    private UserDetailsService userDetailsService;
    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        MailLoginToken mailLoginToken = (MailLoginToken) authentication;
        UserInfo userInfo = (UserInfo)mailLoginToken.getPrincipal();
        if(userInfo == null){
            throw new InternalAuthenticationServiceException("用户不存在");
        }
        return mailLoginToken;
    }

    @Override
    public boolean supports(Class<?> authentication) {
        return (MailLoginToken.class.isAssignableFrom(authentication));
    }




}
